package com.guit.hrms.scheduledTasks;

import com.guit.hrms.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
@EnableScheduling
public class AttendanceTask {

    @Autowired
    private AttendanceService attendanceService;

    // 每月1号凌晨0点执行（Cron表达式：秒 分 时 日 月 周）
    @Scheduled(cron = "0 0 0 1 * ?")
    public void countAttendanceByMonth() {
        LocalDate lastYearMonth = LocalDate.now().minusMonths(1);
        attendanceService.countAttendanceByMonth(lastYearMonth);
    }

    @Scheduled(cron = "0 0 1 * * ?")
    public void addEmpSign() {
        LocalDate checkInDate = LocalDate.now();
        attendanceService.addEmpSign(checkInDate);
    }
}